package com.example.yuejian21.nongfusanquan.yuejian21.base;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.example.yuejian21.nongfusanquan.yuejian21.R;

/**
 * Created by Nongfusanquan on 2017-10-23.
 */

public class BaseFragment extends Fragment {
    protected FragmentManager childManager;
    private FragmentTransaction transaction;
    protected Context context;
    public BaseFragment() {
        context = getActivity();
    }



    @Override
    public void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        childManager = getChildFragmentManager();
    }

    protected void addFragment(Fragment fragment) {
        transaction = childManager.beginTransaction();
        transaction.add(R.id.fragment_container, fragment);
        transaction.commit();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    protected void replaceFragment(Fragment fragment) {
        transaction = childManager.beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }
}

